package com.gxc.jpa;

import com.gxc.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

/**
 * UserRepository.
 *
 * @author 宫新程
 * @since 2019/1/18 11:32 PM
 */
@Transactional
public interface UserRepository
    extends JpaRepository<User, Integer>, JpaSpecificationExecutor<User> {

  @Query(value = "select * from user u where u.id = ?", nativeQuery = true)
  User findByUserId(Integer id);

  @Modifying
  @Query(value = "delete from user where id = ?", nativeQuery = true)
  void deleteByUserId(Integer id);
}
